package com.eye.web.controller.manage;

import com.eye.common.core.controller.BaseController;

import com.eye.system.domain.Device;
import com.eye.system.search.DeviceSearch;
import com.eye.system.service.DeviceService;
import com.eye.system.util.PageResult;
import com.eye.system.util.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/device/")
@Api(tags = "设备")
public class DeviceController extends BaseController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("add")
    @ApiOperation("新增设备")
    public Results addDevice(@RequestBody Device device) {
        Integer addDevice = deviceService.addDevice(device);
        return Results.ok(addDevice);
    }

    @PostMapping("select/paging")
    @ApiOperation("分页条件查询设备")
    public Results selectPaging(@RequestBody DeviceSearch deviceSearch) {
        PageResult pageResult = deviceService.selectPaging(deviceSearch);
        return Results.ok(pageResult);
    }

    @PostMapping("delete")
    @ApiOperation("根据ID删除设备")
    public Results deleteDevice(@RequestParam Integer id) {
        Integer deleteDevice = deviceService.deleteDevice(id);
        return Results.ok(deleteDevice);
    }

    @GetMapping("select")
    @ApiOperation("根据ID查询设备")
    public Results selectById(@RequestParam Integer id) {
        Device device = deviceService.selectById(id);
        return Results.ok(device);
    }

    @PostMapping("update")
    @ApiOperation("根据ID修改设备")
    public Results updateById(@RequestParam Integer id, @RequestBody Device device) {
        Integer updateDevice = deviceService.updateDevice(id, device);
        return Results.ok(updateDevice);
    }

    @GetMapping("activation")
    @ApiOperation("激活设备")
    public Results activation(@RequestParam Integer id) {
        Integer activation = deviceService.activation(id);
        return Results.ok(activation);
    }

}
